package com.example.mobile20306061480509homework;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity2 extends AppCompatActivity {

    private TextView tvMaintitle2;
    private Button btnMaincailiao;
    private TextView textView2;
    private Button btnMainqueding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
       btnMaincailiao.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Intent intent=new Intent(MainActivity2.this,MainActivity.class);
               startActivityForResult(intent,1);
           }
       });
    }
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data){
        super.onActivityResult(requestCode,resultCode,data);
        if (requestCode==1&&resultCode==RESULT_OK){
            textView2.setText(data.getStringExtra("Main2"));
        }
    }


    private void initView() {
        tvMaintitle2 = (TextView) findViewById(R.id.tvMaintitle2);
        btnMaincailiao = (Button) findViewById(R.id.btnMaincailiao);
        textView2 = (TextView) findViewById(R.id.textView2);
        btnMainqueding = (Button) findViewById(R.id.btnMainqueding);
    }
}